package org.brownflat.watergate.service;

import org.brownflat.watergate.dao.BranchDAO;
import org.brownflat.watergate.dao.CommitDAO;
import org.brownflat.watergate.dao.CommitElementDAO;
import org.brownflat.watergate.domain.Branch;
import org.brownflat.watergate.domain.Commit;
import org.brownflat.watergate.domain.CommitElement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.List;

/**
 * <p>&copy Rupert Jones 2012</p>
 *
 * @author rup
 */
@Service
@Transactional
public class DefaultBranchService implements BranchService {
    @Autowired
    private BranchDAO branchDAO;

    @Autowired
    private CommitDAO commitDAO;

    @Autowired
    private CommitElementDAO commitElementDAO;

    @Override
    public Branch findById(int branchId) {
        return branchDAO.findById(branchId);
    }

    @Override
    public void save(Branch branch) {
        branchDAO.upsert(branch);
    }

    @Override
    public void save(Commit commit) {
        commitDAO.upsert(commit);
    }

    @Override
    public Commit findLastCommitFor(Branch branch) {
        return commitDAO.findLastCommitFor(branch);
    }

    @Override
    public Commit findCommit(int id) {
        return commitDAO.findById(id);
    }

    @Override
    public CommitElement findCommitElement(int id) {
        return commitElementDAO.findById(id);
    }

    @Override
    public List<Commit> findReviewTriggerableCommits(Branch branch) {
        return commitDAO.findNotReviewTriggeredFor(branch);
    }

    @Override
    public Collection<Branch> findAll() {
        return branchDAO.findAll();
    }


}
